feat(es/modules): autogenerate AMD module names (#4014)#11822
Draft
MukundaKatta wants to merge 2 commits into
Draft
feat(es/modules): autogenerate AMD module names (#4014)#11822MukundaKatta wants to merge 2 commits into
MukundaKatta wants to merge 2 commits into
Conversation
Adds an `auto_module_id` flag and template placeholders (`[name]`, `[path]`) to `amd::Config.module_id`, so swc can name AMD `define` calls from the file path the way TypeScript's `--outFile` does without requiring a per-file `/// <amd-module name=".../>` directive. - `module_id` accepts templates with `[name]` (file stem) and `[path]` (project-relative path without extension); plain strings still pass through verbatim. - `auto_module_id: true` derives the id from the resolver base when no static id or `<amd-module>` directive is present. - Falls back to the prior anonymous `define([...], fn)` behavior when the resolver is the default no-op one. Closes swc-project#4014.
🦋 Changeset detectedLatest commit: 71a2fab The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Binary Sizes
Commit: ca4dd70 |
Merging this PR will not alter performance
Comparing Footnotes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #4014. Adds
auto_module_idflag and[name]/[path]template placeholders toamd::Config.module_id, mirroring TypeScript--outFilebehavior. Today swc emits anonymousdefine([...], function(...) {...}); this PR lets users opt in to named AMD modules derived from file paths.What's added
crates/swc_ecma_transforms_module/src/amd.rs—module_idtemplate interpolation,auto_module_idflag, helpersbase_name_and_path,interpolate_module_id,derive_auto_module_id.Behavior
module_id: "[name]"— emitsdefine("foo", ...)forfoo.tsmodule_id: "my-lib/[path]"— emitsdefine("my-lib/src/foo", ...)forsrc/foo.tsauto_module_id: true(withoutmodule_id) — derives from file path the way TypeScript doesdefinebehavior. Backwards-compatible.Test plan
cargo test -p swc_ecma_transforms_module: 4 new + 262 amd + 261 umd + 17 path_node + 63 common_js + 262 sys_js — all greencargo fmt --checkclean,cargo clippy --all-targets -- -D warningsclean